package com.cedric.yixianpai.game.Status;

public class DuelHp {
    protected int hp;
    protected int maxHp;

    public DuelHp(int hp) {
        this.hp = hp;
        this.maxHp = hp;
    }

    public DuelHp(int hp, int maxHp) {
        this.hp = hp;
        this.maxHp = maxHp;
        if(this.maxHp<this.hp)//监视生命上限
        {
            throw new IllegalArgumentException("maxHp cannot be less than hp");
        }
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getMaxHp() {
        return maxHp;
    }

    public void setMaxHp(int maxHp) {
        this.maxHp = maxHp;
    }

    public void addHp(int add){
        this.hp+=add;
//        System.out.println("生命增加"+add);
        if(this.hp>this.maxHp){
//            System.out.println("血量已经达到上限！");
            this.hp=this.maxHp;
        }
    }

    public void decHp(int dec){
        if(dec>=0){this.hp-=dec;}
        else{throw new IllegalArgumentException("伤害错误！");}
    }

    public void addMaxHp(int addMax){
        this.maxHp+=addMax;
    }

    public void decMaxHp(int decMax){
        this.maxHp-=decMax;
        if(this.hp>this.maxHp){
            this.hp=this.maxHp;
        }
    }

    /**
     * 两者相加不同
     * @param hp 加的生命
     * @param max 加的生命上限
     */
    public void addHpAndMaxHp(int hp,int max){
        this.addMaxHp(max);
        this.addHp(hp);
    }

    /**
     * 检查存活
     * 返回1为活，0为死
     * @return 1/0
     */
    public boolean survive(){
        return this.maxHp > 0 && this.hp > 0;
    }
}
